package com.wulian.common.interceptor;


import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.wulian.common.constants.CommonConstants;

import javax.servlet.http.HttpServletRequest;

/**
 * 
* @ClassName: FeignConfigInterceptor 
* @Description: TODO(配置feign拦截器,实现token feign之间调用传递使用) 
* @author 马志豪
* @date 2019年9月16日 下午4:13:09 
*
 */
@Configuration
public class FeignConfigInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String url = requestTemplate.url(); 
        if(     !url.contains("/inspectionPlan/inspectionRoleTask")
        		&& !url.contains("/inspectionPlan/inspectionPeopleTask")
                && !url.contains("/spotPlan/spotRoleTask")
                && !url.contains("/spotPlan/spotPeopleTask")
        		&& !url.contains("/user/getUser")
                ) {
        	HttpServletRequest request = attributes.getRequest();
            requestTemplate.header(CommonConstants.USER_TOKEN, request.getHeader(CommonConstants.USER_TOKEN));
        }
    }
}
